/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xrkol.sharelib.dao.AttendanceDao;
import com.xrkol.sharelib.dao.StudentDao;
import com.xrkol.sharelib.entity.Attendance;
import com.xrkol.sharelib.entity.Clazz;
import com.xrkol.sharelib.entity.Student;
import com.xrkol.sharelib.service.AttendanceService;

/**
 * @author peng.xia
 *
 */
@Service
@Transactional
public class AttendanceServiceImpl implements AttendanceService{

    @Autowired
    private AttendanceDao attendanceDao;
    
    @Autowired
    private StudentDao studentDao;
    
    @Override
    public void save(Attendance entity) {
        this.attendanceDao.save(entity);
    }

    @Override
    public void update(Attendance entity) {
        this.attendanceDao.update(entity);
    }

    @Override
    public void deleteByClass(Clazz clazz) {
        this.attendanceDao.deleteByClass(clazz);
    }

    @Override
    public void save(Clazz clazz, String[] stuIds) {
        if(stuIds==null)return;
        for (String id : stuIds) {
            Attendance attendance=new Attendance();
            Student student=this.studentDao.findById(id);
            attendance.setclazz(clazz);
            attendance.setStudent(student);
            this.attendanceDao.save(attendance);
        }
    }

    @Override
    public void delete(String id) {
        this.attendanceDao.delete(id);
    }

    @Override
    public Attendance findById(String id) {
        return this.attendanceDao.findById(id);
    }

    @Override
    public Attendance findByStudent(Student entity) {
        return this.attendanceDao.getByStudent(entity.getId());
    }


}
